package dao;


import function.vehicle;
import entity.User;
import entity.basepinpai;
import entity.car;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

public class carDao {

    List<car> listcollcet= collection.getInstance();
    List<car> listcar = carDB.getInstance();
    List<User> listuser = UserDB.getInstance();
    List<car>listjiage=jiageDB.getInstance();
    List<basepinpai> listpinpai = pinpaiDB.getInstance1();
    List<basepinpai> listchexing = pinpaiDB.getInstance2();
    List<basepinpai> listfuhe=pinpaiDB.getInstance3();
    List<car> listcompare= comparation.getInstance();

    public int findindex(String name) {
        for (int i = 0; i < listuser.size(); i++) {
            if (listuser.get(i).getName().equals(name))
                return i;
        }
        return 0;
    }
    public int findcarindex(String chexing){
        for(int i=0;i<listcar.size();i++){
            if(listcar.get(i).getChexing().equals(chexing))
                return i;
        }
        return 0;
    }
    public boolean checkcollcetion(String chexing){
        if(listuser.get(new vehicle().denglu()).collcet.size()>10){
            listuser.get(new vehicle().denglu()).collcet.remove(0);
        }
        for(int i=0;i<listuser.get(new vehicle().denglu()).collcet.size();i++){
        if(listuser.get(new vehicle().denglu()).collcet.get(i).getChexing().equals(chexing))return false;
    }
    return true;}
    public boolean checkcomparation(String chexing){
        if(listcompare.size()>4){
            listcompare.remove(0);
        }for(int i=0;i<listcompare.size();i++){
            if(listcompare.get(i).getChexing().equals(chexing))return false;
        }
        return true;
    }

    public void jiagequjian(int min,int max) {
        listjiage.clear();
        for (int i = 0; i < listcar.size(); i++) {
            if (listcar.get(i).jiage >= min && listcar.get(i).jiage <= max) {
                listjiage.add(listcar.get(i));
            }
        }
    }
    public void pinpaichexing(String pinpai){
        listfuhe.clear();
        for(int i=0;i<listchexing.size();i++){
            if(listchexing.get(i).getPinpai().equals(pinpai)){
                listfuhe.add(listchexing.get(i));
            }
        }
    }
    public  List<basepinpai> dellist(List<basepinpai> list,String pinpai){
        List<basepinpai> listTemp = new CopyOnWriteArrayList();
        for(int i=0;i<list.size();i++){
            if(list.get(i).getPinpai().equals(pinpai)){
                listTemp.add(list.get(i));
            }
        }
        return listTemp;
    }
    public void delchexing(List<basepinpai> list,String chexing){
        for (int i = list.size() - 1; i >=0 ; i--) {
            if(list.get(i).getChexing().equals(chexing))
                list.remove(i);
        }
    }
    public void delcar(String chexing,List<car> list){
        for (int i = listcar.size() - 1; i >=0 ; i--) {
           if(listcar.get(i).getChexing().equals(chexing))
            list.remove(i);
        }
        }

        public void delcompare(String chexing) {
            for (int i = listcompare.size() - 1; i >= 0; i--) {
                if (listcompare.get(i).getChexing().equals(chexing))
                    listcompare.remove(i);
            }
        }
    public void delcollcet(String chexing,List<car> list) {
        for (int i = listuser.get(new vehicle().denglu()).collcet.size() - 1; i >= 0; i--) {
            if (listuser.get(new vehicle().denglu()).collcet.get(i).getChexing().equals(chexing))
                listuser.get(new vehicle().denglu()).collcet.remove(i);
        }
    }
    public void addchexing(int i,String chexing){
        listchexing.add(new basepinpai(listpinpai.get(i).getPinpai(),chexing));

    }

    public  boolean belongCalendar(Date time, Date from, Date to) {
        Calendar date = Calendar.getInstance();
        date.setTime(time);
        Calendar after = Calendar.getInstance();
        after.setTime(from);
        Calendar before = Calendar.getInstance();
        before.setTime(to);
        if (date.after(after) && date.before(before)) {
            return true;
        } else {
            return false;
        }
    }


}